///**
// * author      : dormi330
// * date        : 2018/6/27
// * project     : mybatis
// * description : 支付一个已经存在的订单
// */
//
//package com.deep.trade.domain.order;
//
//import CommonUtils;
//import TradeException;
//import com.deep.trade.adaptor.required.member.Member;
//import com.deep.trade.adaptor.required.member.MemberService;
//import com.deep.trade.order.InDtoCancelOrder;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//@Service
//public class CommandDeleteOrder {
//
//    private static final int ONLY_ONE_SHOULD_BE_UPDATED = 1;
//
//    @Autowired
//    private OrderRepository orderRepository;
//
//    @Autowired
//    private OrderQueryRepository orderQueryRepository;
//
//    @Autowired
//    private MemberService memberService;
//
//    private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
//
//    /**
//     * 获取 TradeOrder 订单
//     *
//     * @param tradeOrderId
//     * @return
//     * @throws Exception
//     */
//    private TradeOrder assureTradeOrder(String tradeOrderId) throws Exception {
//        if (null == tradeOrderId) throw new TradeException("tradeOrderId cannot be null");
//        TradeOrder tradeOrder = orderQueryRepository.tradeOrderOfId(tradeOrderId);
//        if (null == tradeOrder) {
//            String errMsg = String.format("no such tradeOrder, tradeOrderId=%s", tradeOrderId);
//            throw new TradeException(errMsg);
//        }
//        return tradeOrder;
//    }
//
//    /**
//     * 删除一个订单
//     *
//     * @param inDtoCancelOrder
//     * @throws Exception
//     */
//    @Transactional
//    public void deleteTradeOrder(InDtoCancelOrder inDtoCancelOrder) throws Exception {
//        logger.info("{}, {}", CommonUtils.currentClassAndMethod(), inDtoCancelOrder);
//
//        if (null == inDtoCancelOrder) throw new TradeException("arguments cannot be null");
//
//        String tradeOrderId = inDtoCancelOrder.getTradeOrderId();
//        if (null == tradeOrderId) throw new TradeException("tradeOrderId cannot be null");
//
//        TradeOrder tradeOrder = assureTradeOrder(tradeOrderId);
//
//        // TODO 删除权限校验
//        Member member = memberService.memberOfToken();
//        if (!tradeOrder.getMemberId().equals(member.getId())) {
//            throw new TradeException("no priviledge to delete this order");
//        }
//        // ====== 领域对象操作 =======
//        tradeOrder.delete();
//
//        // ====== 存储 =======
//        if (ONLY_ONE_SHOULD_BE_UPDATED != orderRepository.deleteTradeOrder(tradeOrder)) {
//            throw new TradeException("audit fail, cannot get order to audit");
//        }
//    }
//}
